/*请假窗口显示*/
function showLeaveWin(){
	/*找到div节点并返回*/
	var winNode = $("#leaveWin");
	winNode.fadeIn("slow");
}
/*请假窗口隐藏*/
function hideLeaveWin(){
	/*获取div节点*/
	var winNode = $("#leaveWin");
	winNode.hide("slow");
}
/*任务查看窗口显示*/
function showTaskWin(assignee){
	var assignee="李四";
	$.ajax({
		type:'post',
		url:'/queryTask',
		dataType:'json',
		data:{
			"assignee":assignee
		},
		success : function(data){
			if(data==null){
				alert("no information");
			}else{
				$(".taskData").remove();
				for(var i=0;i<data.length;i++){
					var str='<tr class="taskData"><td style="display: none;"><input value='+data[i].taskId+'></input></td>'+
					'<td><input type="userName" style="height: 30px;" value='+data[i].apply+'></input></td>'+
					'<td><input type="text" name="startTime" style="height: 30px;" value='+data[i].startTime+'></input></td>'+
					'<td><input type="text" name="endTime" style="height: 30px;" value='+data[i].endTime+'></input></td>'+
					'<td><input type="text" name="reason" style="height: 30px; width: 570px;" value='+data[i].reason+'></input></td>'+
					'<td><input type="button" name="agree" onclick="agree('+data[i].taskId+')" value="同意" style="height: 30px;">'+
					'&nbsp;&nbsp;<input type="button" name="unagree" onclick="unagree('+data[i].taskId+')" value="驳回" style="height: 30px;"></td></tr>';
					$("#taskContent").append(str);
				}
				var winNode=$("#taskWin");
				winNode.fadeIn("slow");
			}
		},
		error:function(xhr,status,error){
			alert(error);
		}
	});
}
/**
 * 任务查看窗口隐藏
 */
function hideTaskWin(){
	var winNode=$("#taskWin");
	winNode.hide("slow");
}

function leaveSubmit(){
	var leaveUser=$("#leaveUser").val();
	var startTime=$("#startTime").val();
	var endTime=$("#endTime").val();
	var reason=$("#reason").val();                                                                                                                                                                                                                                                                                    
	var approver=$("#approver").val();
	if(leaveUser==null||leaveUser.length==0){
		alert("请输入请假人姓名！");
		return;
	}
	if(startTime==null||startTime.length==0){
		alert("请输入开始时间！");
		return;
	}
	if(endTime==null||endTime.length==0){
		alert("请输入结束时间！");
		return;
	}else if(startTime>endTime){
		alert("请假时间输入错误！");
		return;
	}
	if(reason==null||reason.length==0){
		alert("请输入请假原因！");
		return;
	}
	if(approver==null||approver.length==0){
		alert("请选择审批人！");
		return;
	}
	var data=leaveUser+","+startTime+","+endTime+","+reason+","+approver;
	//请假窗口结点
	$.ajax({
		type:'post',
		url:'/leaveProcess',
		dataType:'json',
		data:{
			"data":data
		},
		success:function(data){
			alert("请假已提交，请等待审批！");
			$("#leaveUser").val(null);
			$("#startTime").val(null);
			$("#endTime").val(null);
			$("#reason").val(null);
			$("#approver").val(null);
		},
		error:function(xhr, status, error){
			alert(error);
		}
	});
	/*获取div节点*/
	var winNode = $("#leaveWin");
	winNode.hide("slow");
}
/**
 * 同意请假审批
 */
function agree(taskId){
	$.ajax({
		type:'post',
		url:'/complete',
		dataType:'json',
		data:{
			"taskId":taskId,
			"flag":1
		},
		success:function(data){
			alert("完成审批！");
		},
		error:function(xhr,status,error){
			alert(error);
		}
	});
	hideTaskWin();
}
/**
 * 驳回请假审批
 */
function unagree(taskId){
	$.ajax({
		type:'post',
		url:'/complete',
		dataType:'json',
		data:{
			"taskId":taskId,
			"flag":0
		},
		success:function(data){
			alert("完成审批！");
		},
		error:function(xhr,status,error){
			alert(error);
		}
	});
	hideTaskWin();
}
/*查看审批结果*/
function showResultWin(){
	var assignee="张三";
	$.ajax({
		type:'post',
		url:'/result',
		dataType:'json',
		data:{
			"assignee":assignee
		},
		success:function(data){
			if(data==null){
				alert("no infomation!");
			}else{
				$("#raskId").val(data.taskId);
				$("#ruserName").val(data.apply);
				$("#rstartTime").val(data.startTime);
				$("#rendTime").val(data.endTime);
				$("#rreason").val(data.reason);
				$("#leaveResult").val(data.msg==1?'同意':'不同意');
				$("#resultWin").fadeIn("slow");
			}
		},
		error:function(xhr,status,error){
			alert(error);
		}
	});
}
/*请假结果窗口隐藏*/
function hideResultWin(){
	/*获取div节点*/
	var winNode = $("#resultWin");
	winNode.hide("slow");
}